<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // map转对象
        let map1 = new Map([['age', 18], ["name", 'tom'], ['sex', 1], [true, true], ['true', 666]]);
        console.log(map1);
        let obj1 = {}; // 声明一个空对象，用来接受map的数据
        for (let [k, v] of map1) {
            obj1[k] = v
        }
        console.log(obj1);
        // map中的key都是字符串时，可以放心的转换为obj；但是key中有其他类型时，可以能会造成数据的丢失

        // obj装map
        let obj2 = {'age': 18, name: 'Tina', sex: 2, job: 'stu'};
        console.log(Object.entries(obj2)); // entrie返回一个数组，数组的每一项都是一个长度为2的数组
        let map2 = new Map(Object.entries(obj2));
        console.log(map2);
    </script>
</body>

</html>